﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Client
{
    static class TriviaClient
    {

        static StreamReader streamReader;
        static StreamWriter streamWriter;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            TcpClient serverSocket;
            try
            {
                serverSocket = new TcpClient("localHost", 9001);
            }
            catch
            {
                Console.WriteLine("Failed to connect to server");
                return;
            }
            streamReader = new StreamReader(serverSocket.GetStream());
            streamWriter = new StreamWriter(serverSocket.GetStream());
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //first screen to get name
            Application.Run(new ClientForm(streamWriter));

            //the waiting screen
            Application.Run(new WaitingScreen(streamReader));


            //question screen
            string question, a, b, c, d;
            while (true)
            {
                question = streamReader.ReadLine();
                a = streamReader.ReadLine();
                b = streamReader.ReadLine();
                c = streamReader.ReadLine();
                d = streamReader.ReadLine();
                Application.Run(new QuestionForm(streamWriter, question, a, b, c, d));

            }
            //Application.Exit();
         
        }
    }
}
